package com.lottery.ruok.lottrey.adapter;

import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.lottery.ruok.lottrey.R;
import com.lottery.ruok.lottrey.activity.FilterOrderActivity;
import com.lottery.ruok.lottrey.retrofitModule.response.GetWholeCategoryResponse;

import java.util.ArrayList;

/**
 * Created by ASUS on 2017/11/13.
 */

public class FilterOrderAdapter extends BaseAdapter {
    private ArrayList<GetWholeCategoryResponse> getWholeCategoryResponses;
    private int index;
    private FilterOrderActivity filterOrderActivity;
    public FilterOrderAdapter(ArrayList<GetWholeCategoryResponse> getWholeCategoryResponse, int i, FilterOrderActivity filterOrderActivity){
        index = i;
        getWholeCategoryResponses = getWholeCategoryResponse;
        GetWholeCategoryResponse.ItemsBean itemsBean = new GetWholeCategoryResponse.ItemsBean();
        itemsBean.setName("全部");
        getWholeCategoryResponses.get(index).getItems().add(0, itemsBean);
        this.filterOrderActivity = filterOrderActivity;
    }

    @Override
    public int getCount() {
        if(getWholeCategoryResponses.size() > index){
            return getWholeCategoryResponses.get(index).getItems().size();
        } else {
            return 0;
        }
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder;
        if (view != null) {
            holder = (ViewHolder) view.getTag();
        } else {
            view = LayoutInflater.from(filterOrderActivity).inflate(R.layout.filter_order_item, null);
            holder = new ViewHolder();
            holder.name = view.findViewById(R.id.name);
            view.setTag(holder);
        }

        holder.name.setText(getWholeCategoryResponses.get(index).getItems().get(i).getName());
        if (filterOrderActivity.mCurrentName.equals(getWholeCategoryResponses.get(index).getItems().get(i).getName())) {
            holder.name.setTextColor(Color.parseColor("#ffffff"));
            holder.name.setBackgroundResource(R.drawable.bg_corners_100_3);
        } else {
            holder.name.setTextColor(Color.parseColor("#3f3f3f"));
            holder.name.setBackgroundResource(R.drawable.bg_corners_100_12);
        }

        return view;
    }

    static class ViewHolder {
        TextView name;
    }
}